﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JVP.Gateway;
using JVP.Infrastructure;


namespace JeevanVaisya
{
    public partial class Login : Form
    {
        Gateway gateway = new Gateway();
        public int choseUser = 0;
        public string userName;
        public Login()
        {
            InitializeComponent();            
            btnLogin.Click += new EventHandler(btnLogin_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);            
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            Login.ActiveForm.Close();
        }

        void btnLogin_Click(object sender, EventArgs e)
        {            
            if (txtUserName.Text != "" && txtPassword.Text != "")
            {                
                if (gateway.isValidUser(txtUserName.Text, txtPassword.Text))
                {
                    if (txtUserName.Text == "admin")
                        choseUser = 1;
                    else
                        choseUser = 2;
                    userName = txtUserName.Text;
                    this.Close();                    
                    AdminHome adminHome = new AdminHome(userName);
                    adminHome.ShowDialog();
                }
                else
                    lblError.Text = "Authentication Failed";
            }
            else
                lblError.Text = "Enter User Name & Password";            
        }       
    }
}
